/*
 * @Author: WangGuojian 1085844536@qq.com
 * @Date: 2023-12-20 13:53:28
 * @LastEditTime: 2024-06-05 12:28:28
 * @LastEditors: WangGuojian 1085844536@qq.com
 * @FilePath: \HelloWorldd:\Developer\WGJ\VSCode_WorkSpace\Cpp\c-learning\code\arr\simple_test.c
 * @Description:
 */
#include <stdio.h>
#include <stdlib.h>

static void fibonacci(void)
{
    int i,tmp;
    int fib[10] = {1, 1};

    for ( i = 2; i < sizeof(fib)/sizeof(fib[0]); i++)
    {
        fib[i] =fib[i-1]+fib[i-2];
    }
    for ( i = 0; i < sizeof(fib)/sizeof(fib[0]); i++)
    {
        printf("%d\n", fib[i]);
    }

    i=0;
    int j=sizeof(fib)/sizeof(fib[0])-1;

    while (i<j)
    {
        /* code */
        tmp=fib[i];
        fib[i]=fib[j];
        fib[j]=tmp;

        i++;
        j--;
    }

    for (i = 0; i < sizeof(fib)/sizeof(fib[0]); i++)
    {
        /* code */
        printf("%d\n", fib[i]);
    }

    printf("\n");

    return;
}

#define N 10

static void sort1(void)
{
    int a[N] = {12, 8, 45, 30, 98, 67, 2, 7, 68, 11};
    int i, j, tmp;

    for ( i = 0; i < N; i++)
    {
        printf("%d ", a[i]);
    }
    printf("\n");

    for (int i = 0; i < (N - 1); i++)
    {
        for (int j = 0; j < N - 1 - i; j++)
        {
            if (a[j] > a[j+1])
            {
                /* code */
                tmp = a[j];
                a[j] = a[j+1];
                a[j+1] = tmp;
            }

        }
    }

    for ( i = 0; i < N; i++)
    {
        printf("%d ", a[i]);
    }
    printf("\n");

}

static void sort2(void)
{
    int i, j, k, tmp;
    int a[N]={23, 45, 90, 76, 13, 55, 76, 45, 3, 8};

    for (i = 0; i < sizeof(a)/sizeof(a[i]); i++)
    {
        /* code */
        printf("%d ", a[i]);
    }
    printf("\n");

    for (i = 0; i < N - 1; i++)
    {
        k = i;
        for (j = i + 1; j < N; j++)
        {
            if (a[j] < a[k])
            {
                k = j;
            }
        }
        if (i != k)
        {
            tmp = a[i];
            a[i] = a[k];
            a[k] = tmp;
        }
    }


    for (i = 0; i < sizeof(a)/sizeof(a[i]); i++)
    {
        /* code */
        printf("%d ", a[i]);
    }
    printf("\n");

}

static void base_convert(void)
{
    int num, base, i = 0;
    int n[128];

    printf("Please enter the converted num:");
    scanf("%d", &num);
    printf("Please enter the base:");
    scanf("%d", &base);

    do
    {
        n[i] = num % base;
        num = num / base;
        i++;
    } while (num != 0);

    for (i--; i >= 0; i--)
    {
        /* code */
        if (n[i] >= 0 && n[i] <= 9)
        {
            printf("%d", n[i]);
        }
        else
        {
            printf("%c", n[i] - 10 + 'A');
        }
    }
}

static void primer(void)
{
    int i, j;
    char primer[1001] = {0};

    for (i = 2; i < 1001; i++)
    {
        if (primer[i] == 0)
        {
            for ( j = i * 2; j < 1001; j += i)
            {
                primer[j] = -1;
            }
        }
    }

    for (i = 0; i < 1001; i++)
    {
        if (primer[i] == 0)
        {
            printf("%d is a primer\n", i);
        }
    }
}

int main()
{
    // fibonacci();
    // sort1();
    // sort2();
    // base_convert();
    primer();
}